package flst.ipiweb.struts.action.article;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;



import flst.ipiweb.service.ServiceArticle;

public class GenererRefArticleAction extends Action{
	
	public ActionForward execute(
			ActionMapping mapping, 
			ActionForm form,
			HttpServletRequest request, 
			HttpServletResponse response)
			throws Exception {
		
			ServiceArticle sArticle = new ServiceArticle();
			int refArticle = sArticle.genererRefArticle();
			Map<String, Integer> map = new HashMap<String, Integer>();
			map.put("ref", refArticle);
			JSONObject jsonObject = JSONObject.fromObject( map );

			response.setContentType("application/json");
			PrintWriter out = response.getWriter();
			out.println(jsonObject.toString());
			out.flush();
			return null;
		}
	
}
